package com.dsh.storeManagement.controller;

import com.dsh.model.Result;
import com.dsh.storeManagement.entity.vo.AdminAreaVo;
import com.dsh.storeManagement.entity.vo.AreaNameVo;
import com.dsh.storeManagement.entity.dto.GradeDto;
import com.dsh.storeManagement.entity.dto.UpdateAreaDto;
import com.dsh.storeManagement.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "片区设置")
@RestController
@RequestMapping("area")
public class AreaController {
    @Resource
    AreaService areaService;
    @ApiOperation(value = "根据片区id查询",response = AdminAreaVo.class)
    @ApiImplicitParam(paramType="query", name = "aid", value = "片区Id", required = true, dataType = "int")
    @GetMapping("selectAreaAllById")
    public Result selectAreaAllById( int id){
        AdminAreaVo adminAreaVo = areaService.selectAreaAllById(id);
        return Result.success(adminAreaVo,"");
    }
    @ApiOperation(value = "查看加盟级别" ,response = GradeDto.class)
    @GetMapping("selectGrade")
    public Result selectGrade(){
        List<GradeDto> gradeDtos = areaService.selectGrade();
        return Result.success(gradeDtos,"");
    }
    @ApiOperation("添加片区")
    @PostMapping("addArea")
    private Result addArea(@RequestBody AreaNameVo areaNameVo){
        int i = areaService.addArea(areaNameVo);
        return Result.success(i,"");
    }
    @ApiOperation("修改片区")
    @PostMapping("updateArea")
    private Result updateArea(@RequestBody UpdateAreaDto updateAreaDto){
        int i = areaService.updateArea(updateAreaDto);
        return Result.success(i,"");
    }
}
